from django.urls import converters,register_converter

class CategoryConverter(object):
    #0-9 a-z A-Z _
    #python
    #python+flask
    #python+flask+django
    regex = r'\w+|(\w+\+\w+)+'

    def to_python(self,value):
        #python+flask  => ['python','flask']
        result = value.split("+")
        return result


    def to_url(self,value):
        #value ：['python','flask']
        #python+flask
        if isinstance(value,list):
            result = "+".join(value)
            return result
        else:
            raise RuntimeError("转化url的时候 分类参数必须为列表")
register_converter(CategoryConverter,'kangbazi')